package com.shopping.servlets;

import com.shopping.dao.CarDao;
import com.shopping.dao.FlowerDao;
import com.shopping.dao.impl.CarDaoImpl;
import com.shopping.dao.impl.FlowerDaoImpl;
import com.shopping.model.Flower;
import com.shopping.model.Flower;
import com.shopping.model.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @ClassName: FlowerServlet
 * @Description: TODO
 * @Author: JiaShiXi
 * @Date: 2021/3/20 15:17
 * @Version: 1.0
 **/
@WebServlet("/flower/flower.do")
public class FlowerServlet extends BaseServlet {
    FlowerDao flowerDao = new FlowerDaoImpl();
    /**
     * 获取花卉列表
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     */
    protected void queryFlower(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Flower> flowerList  = flowerDao.queryFlower();
        request.setAttribute("flowerList",flowerList);
        User user = (User) request.getSession().getAttribute("user");
        if (user!=null){
            CarDao carDao = new CarDaoImpl();
            int count = carDao.countCar(user.getUser_id());
            request.setAttribute("count",count);
        }
        request.getRequestDispatcher("/showFlowerList.jsp").forward(request,response);
    }

}
